#!/usr/bin/env bash
containerName="minio"
echo '>>> Please later ... ...'
set -e
sudo docker pull minio/minio:latest |
   grep "Image is up to date" ||
   (echo Already up to date. Exiting... && exit 0)


echo '>>> Get old container id'
CID=$(sudo docker ps --all | grep ${containerName} | awk '{print $1}')
echo $CID


echo '>>> Stopping and deleting old container'
if [ "$CID" != "" ];
then
  sudo docker stop $CID
  sudo docker rm $CID
fi
echo '>>> Starting new container'

docker run -p 9000:9000 --name ${containerName}  -d --privileged=true --restart=always -e "MINIO_ACCESS_KEY=minio" -e "MINIO_SECRET_KEY=minio123456" -v /docker/minio/data:/data -v /docker/minio/config:/root/.minio minio/minio server /data
